package jp.sourceforge.akjrcp.text_douga.video;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import jp.sourceforge.akjrcp.text_douga.VideoData;
import jp.sourceforge.akjrcp.util.image.ImageUtils;

public class DirectoryVideoWriter extends AbstractVideoWriter{
	private File exportDir;
	private String exportHeader="";
	
	public DirectoryVideoWriter(File exportDir,File workingDir){
		this.exportDir=exportDir;
		setWorkingDir(workingDir);
	}
	
	public File getExportDir() {
		return exportDir;
	}
	public void setExportDir(File exportDir) {
		this.exportDir = exportDir;
	}
	
	public boolean writeFrame(VideoData videoData, BufferedImage image) throws IOException {
		if(writed==maxFrame){
			//return true;
			}
		File imageFile=new File(exportDir.getAbsolutePath()+"\\"+VideoUtils.toFileName(exportHeader,writed+1,5,"jpg"));
		ImageUtils.writeJpegWithQuality(image, imageFile, 1.0f);
		writed++;
		if(writed==maxFrame){
		return true;
		}else{
		return false;
		}
	}

	public void close() throws IOException {
		//do nothing
	}
}
